package com.zhaojiadi.abstractfactory.factory;

import com.zhaojiadi.abstractfactory.util.ClassLoaderUtils;
import com.zhaojiadi.abstractfactory.workshop.ICacheAdapter;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @Date: 2021/8/26
 * @Description:
 */
public class JDKInvocationHandler implements InvocationHandler {

    private ICacheAdapter cacheAdapter;

    public JDKInvocationHandler(ICacheAdapter cacheAdapter) {
        this.cacheAdapter = cacheAdapter;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        return ICacheAdapter.class.getMethod(method.getName(), ClassLoaderUtils.getClassByArgs(args)).invoke(cacheAdapter,args);
    }
}
